/**
 * 
 */
package com.aodesoft.demo.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aodesoft.base.BaseAction;
import com.aodesoft.demo.service.DemoService;
import com.aodesoft.pojo.Demo;
import com.aodesoft.power.AdmItp;
import com.aodesoft.power.FwdItp;

/**
 * 
 * @author tang
 * @date 2011-12-3
 */
@Controller
@Scope("prototype")
public class DemoAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	//记录总数，每页显示数（默认15条），和页码
	private int pageCount,pageSize=15,pageIndex; 
	private List<Demo> demos;
	@Resource
	private DemoService demoService;
	
	/**
	 * 分页查询 
	 * @author tang
	 * @date 2011-12-11
	 * @return
	 */
	//后台拦截
	@AdmItp
	public String getList(){
		pageCount=demoService.count();
		
		//页码判断
		int allPage=pageCount%pageSize==0?pageCount/pageSize:pageCount/pageSize+1;
		pageIndex=pageIndex<0?0:pageIndex;
		pageIndex=pageIndex>=allPage?allPage-1:pageIndex;
		long start=System.currentTimeMillis(); //获取最初时间
		
			demos=demoService.getList(pageSize,pageIndex);
		
		long end=System.currentTimeMillis(); //获取运行结束时间
		System.out.println("二级缓存测试  查询执行时间： "+(end-start)+"ms");
		
		
		return view("/demo/demoList.jsp");
	}
	/**
	 * 跳转测试
	 * @author tang
	 * @date 2011-12-10
	 */
	//前台拦截
	@FwdItp
	public String testJump(){
		//redirect跳转
		return view("/demo/testJump.jsp");
	}
	/************************强大的分割线*****************************************/
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getPageIndex() {
		return pageIndex;
	}
	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}
	public List<Demo> getDemos() {
		return demos;
	}
	public void setDemos(List<Demo> demos) {
		this.demos = demos;
	}
	public int getTotal() {
		return pageCount;
	}
	public void setTotal(int total) {
		this.pageCount = total;
	}
	public int getPageCount() {
		return pageCount;
	}
	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}
}
